package com.base.app.controller;

import java.util.List;
import java.util.Arrays;

import com.base.app.domain.vo.TAppKeyVo;
import com.base.app.service.ITAppKeyService;
import com.base.common.annotation.Log;
import com.base.common.annotation.RepeatSubmit;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;

import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.base.common.core.controller.BaseController;
import com.base.common.core.domain.PageQuery;
import com.base.common.core.domain.R;
import com.base.common.core.validate.AddGroup;
import com.base.common.core.validate.EditGroup;
import com.base.common.enums.BusinessType;
import com.base.common.utils.poi.ExcelUtil;
import com.base.app.domain.bo.TAppKeyBo;
import com.base.common.core.page.TableDataInfo;

/**
 * 应用历史密钥
 *
 * @author base
 * @date 2023-10-17
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/appKey")
public class TAppKeyController extends BaseController {

    private final ITAppKeyService iTAppKeyService;

    /**
     * 查询应用历史密钥列表
     */
// @SaCheckPermission("app:appKey:list")
    @GetMapping("/list")
    public R<TableDataInfo<TAppKeyVo>> list(TAppKeyBo bo, PageQuery pageQuery) {
        return R.ok(iTAppKeyService.queryPageList(bo, pageQuery));
    }

    /**
     * 导出应用历史密钥列表
     */
    //   @SaCheckPermission("app:appKey:export")
    @Log(title = "应用历史密钥", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TAppKeyBo bo, HttpServletResponse response) {
        List<TAppKeyVo> list = iTAppKeyService.queryList(bo);
        ExcelUtil.exportExcel(list, "应用历史密钥", TAppKeyVo.class, response);
    }

    /**
     * 获取应用历史密钥详细信息
     *
     * @param autoId 主键
     */
    //    @SaCheckPermission("app:appKey:query")
    @GetMapping("/{autoId}")
    public R<TAppKeyVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String autoId) {
        return R.ok(iTAppKeyService.queryById(autoId));
    }

    /**
     * 新增应用历史密钥
     */
//     @SaCheckPermission("app:appKey:add")
    @Log(title = "应用历史密钥", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TAppKeyBo bo) {
        return toAjax(iTAppKeyService.insertByBo(bo));
    }

    /**
     * 修改应用历史密钥
     */
    //   @SaCheckPermission("app:appKey:edit")
    @Log(title = "应用历史密钥", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TAppKeyBo bo) {
        return toAjax(iTAppKeyService.updateByBo(bo));
    }

    /**
     * 删除应用历史密钥
     *
     * @param autoIds 主键串
     */
    //  @SaCheckPermission("app:appKey:remove")
    @Log(title = "应用历史密钥", businessType = BusinessType.DELETE)
    @DeleteMapping("/{autoIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] autoIds) {
        return toAjax(iTAppKeyService.deleteWithValidByIds(Arrays.asList(autoIds), true));
    }
}
